package com.jhhc.BDMS.System.Util;

import com.jhhc.BDMS.System.Pojo.BDMS_SYS_ADMINMAP_B;
import com.jhhc.BDMS.System.Pojo.RegionArea;
import com.jhhc.BDMS.System.Pojo.RegionAreaData;
import com.jhhc.BDMS.System.Serivce.BDMS_SYS_ADMINMAP_BService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Service
public class GetADMINMAPUtil {
    @Autowired
    private BDMS_SYS_ADMINMAP_BService bdms_sys_adminmap_bService;

    public RegionArea getAdminMap(Integer Pid){
        List<RegionArea> regionAreas = new ArrayList<>();
        //最大返回对象
        RegionArea regionArea = new RegionArea();
        //获取数据
        List<BDMS_SYS_ADMINMAP_B> bdms_sys_adminmap_bs =   bdms_sys_adminmap_bService.selectByPid(Pid);
        //循环遍历
        for (BDMS_SYS_ADMINMAP_B bdms_sys_adminmap_b:bdms_sys_adminmap_bs){
            if (bdms_sys_adminmap_b.getArealevel()==1){
                regionArea.setAreaLevel(bdms_sys_adminmap_b.getArealevel());
                regionArea.setAreaName(bdms_sys_adminmap_b.getAreaname());
                RegionAreaData regionAreaData = new RegionAreaData();
                regionAreaData.setPointName(bdms_sys_adminmap_b.getPointname());
                regionAreaData.setPointXY(bdms_sys_adminmap_b.getPointxy());
                List<String> boundarys = Arrays.asList(bdms_sys_adminmap_b.getBoundarys().split(";"));
                regionAreaData.setBoundarys(boundarys);
                regionArea.setRegionAreaData(regionAreaData);
            }else {
                //第二层对象
                RegionArea regionArea2 = new RegionArea();
                regionArea2.setAreaLevel(bdms_sys_adminmap_b.getArealevel());
                regionArea2.setAreaName(bdms_sys_adminmap_b.getAreaname());
                RegionAreaData regionAreaData2 = new RegionAreaData();
                regionAreaData2.setPointName(bdms_sys_adminmap_b.getPointname());
                regionAreaData2.setPointXY(bdms_sys_adminmap_b.getPointxy());
                List<String> boundarys = Arrays.asList(bdms_sys_adminmap_b.getBoundarys().split(";"));
                regionAreaData2.setBoundarys(boundarys);
                regionArea2.setRegionAreaData(regionAreaData2);
                regionAreas.add(regionArea2);

            }
        }
        System.out.println(regionAreas.size());
        regionArea.setRegionAreas(regionAreas);


       return regionArea;

    }








}
